home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / lib / partman / finish.d / 10clear_partitions next >
Text File  |  2009-10-28  |  3KB  |  116 lines

  1. #! /bin/sh
  2. # Remove critical files to ensure we don't end up with a mixed system.
  3.  
  4. . /lib/partman/lib/base.sh
  5.  
  6. failed () {
  7.     db_progress STOP
  8.     db_input critical partman-target/clear_partitions_failed || true
  9.     db_go || true
  10.     exit 1
  11. }
  12. count=0
  13. partitions=$(
  14. for dev in $DEVICES/*; do
  15.     [ -d "$dev" ] || continue
  16.     cd $dev
  17.     open_dialog PARTITIONS
  18.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  19.         [ -f "$id/method" ] || continue
  20.         [ -f "$id/use_filesystem" ] || continue
  21.         [ -f "$id/mountpoint" ] || continue
  22.         [ "$fs" != free ] || continue
  23.         [ -f "$id/format" ] && continue
  24.         [ -f "$id/formatted" ] && continue
  25.         count=$(($count + 1))
  26.         mp="$(cat "$id/mountpoint")"
  27.         echo "$mp,$path"
  28.     done
  29.     close_dialog
  30. done | sort
  31. )
  32.  
  33. [ -n "$partitions" ] || exit 0
  34.  
  35. echo "Considering $partitions." | tr '\n' ' ' | logger -t clear_partitions
  36.  
  37. tmp="/mnt/tmpmount"
  38. mkdir -p "$tmp"
  39. template=partman-target/clear_partitions_progress
  40. db_progress START 0 $count ubiquity/install/title
  41. db_progress INFO $template
  42. to_delete=""
  43. for part in $partitions; do
  44.     mp="${part%,*}"
  45.     path="${part#*,}"
  46.     if [ "$mp" = "/" ]; then
  47.         mount $path $tmp || failed
  48.         for x in bin dev etc lib lib32 lib64 proc sbin sys; do
  49.             [ -e "$tmp/$x" ] && (rm -rf "$tmp/$x" &&
  50.             logger -t clear_partitions "Removing $x from / ($path)." ||
  51.             failed)
  52.         done
  53.         for x in "$tmp/usr/"* "$tmp/var/"*; do
  54.             case "$x" in
  55.                 $tmp/usr/local|$tmp/usr/src|$tmp/var/local)
  56.                 continue
  57.                 ;;
  58.             esac
  59.             [ -e "$x" ] && (rm -rf "$x" &&
  60.             logger -t clear_partitions "Removing ${x#$tmp/} from / ($path)." ||
  61.             failed)
  62.         done
  63.         for x in $tmp/initrd* $tmp/vmlinuz*; do
  64.             [ -e "$x" ] && (rm -rf "$x" || failed)
  65.         done
  66.         
  67.         # /home could be a symlink.
  68.         [ -f "$tmp/home" ] && (rm "$tmp/home" || failed)
  69.  
  70.         # / could have the wrong owner.
  71.         chown root:root $tmp
  72.         
  73.         # Preserve the UID, if possible.
  74.         db_get passwd/username || true
  75.         username="$RET"
  76.         if [ -n "$username" ] && [ -d "$tmp/home/$username" ]; then
  77.             uid="$(stat -c %u "$tmp/home/$username")"
  78.             if [ -n "$uid" ] && [ "$uid" != 0 ]; then
  79.                 db_set passwd/user-uid "$uid" || true
  80.             fi
  81.         fi
  82.         umount $tmp
  83.     elif [ "$mp" = "/home" ]; then
  84.         mount $path $tmp || failed
  85.         # Preserve the UID, if possible.
  86.         db_get passwd/username || true
  87.         username="$RET"
  88.         if [ -n "$username" ] && [ -d "$tmp/$username" ]; then
  89.             uid="$(stat -c %u "$tmp/$username")"
  90.             if [ -n "$uid" ] && [ "$uid" != 0 ]; then
  91.                 db_set passwd/user-uid "$uid" || true
  92.             fi
  93.         fi
  94.         umount $tmp
  95.     else
  96.         case "$mp" in
  97.             /usr/local|/usr/local/*|/var/local|/var/local/*|/usr/src|/usr/src/*)
  98.             logger -t clear_partitions "Skipping $mp ($path)."
  99.             continue
  100.             ;;
  101.         esac
  102.         for x in bin dev etc lib lib32 lib64 proc sbin usr var sys; do
  103.             if echo "$mp" | egrep -q "^/$x(\$|/)"; then
  104.                 mount $path $tmp || failed
  105.                 logger -t clear_partitions "Removing everything from $mp ($path)."
  106.                 rm -rf $tmp/* || failed
  107.                 umount $tmp
  108.                 break
  109.             fi
  110.         done
  111.     fi
  112.     db_progress STEP 1
  113. done
  114. db_progress STOP
  115. rmdir $tmp
  116.